package com.example.su_shi_tan_wallet

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.su_shi_tan_bas_lib.base.BaseFragmentEx
import com.example.su_shi_tan_bas_lib.base.BaseLazyDataBindingFragment
import com.example.su_shi_tan_core.arouter.WalletARouter
import com.example.su_shi_tan_core.arouter.WalletARouterParams
import com.example.su_shi_tan_core.constant.SignUserBeanHolder
import com.example.su_shi_tan_core.db.UserInfoBeanHolder
import com.example.su_shi_tan_wallet.databinding.WalletHeaderFragmentBinding

@Route(path = WalletARouter.WalletHeaderFragment)
class WalletHeaderFragment : BaseLazyDataBindingFragment<WalletHeaderFragmentBinding>(),
    View.OnClickListener {

    @JvmField
    @Autowired(name = WalletARouterParams.tokenType)
    var tokenType: String = ""

    private var visible = true

    override fun layoutId(): Int {
        return R.layout.wallet_header_fragment
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mSuperBackPressedSupport=false
    }


    override fun initView(view: View) {

        showMoney()
    }

    @SuppressLint("SetTextI18n")
    private fun showMoney() {
        val signUser = SignUserBeanHolder.getSignUser()
        viewBinder.titleTv.text = "${tokenType}-${_mActivity.getString(R.string.all_capture)}"
        viewBinder?.cnyTv?.visibility = View.VISIBLE
        var usdTvStr = ""
        var cnyTvStr = ""
        when (tokenType) {
            WalletARouterParams.SST -> {

            }
            WalletARouterParams.FVC -> {

            }
            WalletARouterParams.TD -> {

            }
            WalletARouterParams.LD -> {
                usdTvStr = "${signUser?.integral}"
                cnyTvStr = ""
//                viewBinder?.usdTv?.text = "${signUser?.integral}"
                viewBinder?.cnyTv?.visibility = View.GONE
            }
        }

        if (visible) {
            viewBinder?.usdTv?.text = usdTvStr
            viewBinder?.cnyTv?.text = cnyTvStr
        } else {

            viewBinder?.usdTv?.text = cryptStr(usdTvStr)
            viewBinder?.cnyTv?.text = cryptStr(cnyTvStr)
        }
    }

    private fun cryptStr(mStr: String): String {
        var mCryptStr = ""
        mStr.forEach { _ ->
            mCryptStr += "*"
        }
        return mCryptStr
    }


    override fun lazyInit() {
        viewBinder.onViewClick = this
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.visibleTv -> {
                visible = !visible
                showMoney()
            }
        }
    }


}